<?php
/**
 * Pertyler
 * Object Browser's Table's Objects Page
 *
 * @author	Emre Hasegeli <hasegeli@gmail.com>
 * @license	GNU General Public License v3
 */

namespace Pertyler;

require_once 'main.php';

if((empty($page->ParentTable)) OR (empty($page->ParentRow)) OR (empty($page->Table)) OR (empty($page->Column)))
	die;

$parentTable = Pertyler_Table::Select($page->ParentTable);

$parentRow = $parentTable->SelectRow($page->ParentRow);

$table = Pertyler_Table::Select($page->Table);

$column = $table->SelectColumn($page->Column);

$treeView = new \KoolTreeView('treeView');

$treeView->imageFolder = $iconsFolder;

$treeView->showLines = true;

if($table->ConnectorTable())
	foreach($table->SelectRelatedRowArray($parentRow, $column) AS $row)
	{
		$link = new Link('ObjectBrowser.php',
				'body');

		$link->ParentTable = $table->SelectParentTable()->id();

		$link->Row = $row->SelectParentRow()->id();

		$treeView->Add('root',
				$row->SelectParentRow()->id(),
				$link->Html($row->SelectParentRow()),
				false,
				'page.gif');
	}
else
	foreach($table->SelectRelatedRowArray($parentRow, $column) AS $row)
	{
		$link = new Link('ObjectBrowser.php', 'body');

		$link->ParentTable = $table->id();

		$link->Row = $row->id();

		$treeView->Add('root',
				$row->id(),
				$link->Html($row),
				false,
				'page.gif');
	}

$treeView->isSubTree = true;

$treeView->width = '250px';

echo $treeView->Render();